package day0213;

import java.util.Arrays;
import java.util.Scanner;

public class ArrayDemo05 {

    public static void main(String[] args) {
        /*
            添加元素
         */

        int[] arr = {1, 2, 3, 4, 5};

        int[] arr1 = new int[arr.length + 1];

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入下标：");
        int index = sc.nextInt();
        System.out.println("请输入数值：");
        int num = sc.nextInt();

        // 复制
        System.arraycopy(arr, 0, arr1, 0, index);
        System.arraycopy(arr, index, arr1, index + 1, arr.length - index);

        arr1[index] = num;

        System.out.println(Arrays.toString(arr1));
    }
}
